package 笔试.网易;

import java.util.Arrays;
import java.util.Scanner;

//纸张分配
public class Demo3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String[] arr = str.split("\\s+");
        int[] nums = new int[arr.length];
        for(int i=0;i<arr.length;i++){
            nums[i] = Integer.valueOf(arr[i]);
        }
        System.out.println(getCandy(nums));
    }
    //从左至右从右至左各遍历一次
    public static int getCandy(int[] num){
        if(num==null) return 0;
        if(num.length<=1) return 1;
        int len = num.length;
        int[] help = new int[len];
        Arrays.fill(help,1);
        for(int i=1;i<len;i++){
            if(num[i]>num[i-1]){
                help[i] = help[i-1]+1;
            }else{
                help[i] = 1;
            }
        }
        for (int i = len-2; i >=0 ; i--) {
            if(num[i]>num[i+1]){
                help[i] = Math.max(help[i],help[i+1]+1);
            }
        }
        if(help.length>=3){
            if(num[len-1]>num[len-2] || num[len-1]>num[0]){
                help[len-1] = Math.max(Math.max(help[len-1],help[len-2]+1),help[0]+1);
            }
        }
        int sum = 0;
        for (int t : help) {
            sum += t;
        }
        return sum;
    }
}
